﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Logging;

namespace MMITIntegration
{
    public class MobipayOutput
    {
        private string code = "";

        public string Code
        {
            get { return code; }
            set { code = value; }
        }
        private string details = "";

        public string Details
        {
            get { return details; }
            set { details = value; }
        }
        private string txvalue = "";

        public string Value
        {
            get { return txvalue; }
            set { txvalue = value; }
        }
        private string result = "";

        public string Result
        {
            get { return result; }
            set { result = value; }
        }

        public static MobipayOutput FromString(string Xml)
        {

            // assume input element is an XML, in other case an exception will be thrown and captured
            XmlDocument doc = new XmlDocument();

            //Logging Raw XML from Mobipay
            Dictionary<string, object> d = new Dictionary<string, object>();
            SynkronLogger Log = new SynkronLogger("MMITCore");

            d.Add("XML received from Mobipay", Xml);
            Log.WriteInformation(564232345, "XML received from Mobipay", d);


            doc.LoadXml(Xml);
            XmlElement root = doc.DocumentElement;
                      
            MobipayOutput bean = new MobipayOutput();

            

                foreach (XmlNode xnode in doc.FirstChild.ChildNodes)
                {
                    switch (xnode.Name)
                    {
                        case "Code":
                            bean.Code = xnode.InnerText;
                            break;

                        case "Details":
                            bean.Details = xnode.InnerText;
                            break;

                        case "Value":
                            bean.Value = xnode.InnerText;
                            break;

                        case "Result":
                            bean.Result = xnode.InnerText;
                            break;
                    }

                }
                          
            
            return bean;
        }
    }
}